/*
// +----------------------------------------------------------------------
// | 南昌速翔网络科技有限公司
// +----------------------------------------------------------------------
// | QQ技术：1424445608   电 话/微信：15622289461
// +----------------------------------------------------------------------
// | 请务必尊重知识产权 严格保证不恶意传播产品源码、不得直接对产品本身
// | 进行二次转售或倒卖、不得对产品进行简单包装后声称为自己的产品等。
// | 否则我们有权利收回产品，并根据事态轻重追究相应法律责任。
// +----------------------------------------------------------------------
// | Copyright (c) 2019-2020 http://www.suxiangw.com/ All rights reserved.
// +----------------------------------------------------------------------
*/
// // 测试服务器域名
var _sx_gurl = 'http://live.kxg99.com/';
var _sx_gurl1 = 'http://live.api.kxg99.com/api/';

// 测试本地域名
// var _sx_gurl = 'http://test.live.hqtuite.cn/';
// var _sx_gurl1 = 'http://test.dev.hqtuite.cn/api/';
// var _sx_gurl = 'http://dev.zhaojianchn.cn/';
// var _sx_gurl1 = 'http://devs.zhaojianchn.cn/api/';
var _sx_url = _sx_gurl + 'index.php/api/';
var _sx_qiniu = 'http://qiniu.live.kxg99.com/';
var picurl = "http://qiniu.live.kxg99.com/yuzhibo";
// 统一执行代码
function _init_ad() {
	// if(!adName){
	//   ad_vip = false;
	//   return;
	// }
	if (_getPrefs('_config')) {
		if (_getPrefs('_config').config.app == 1) {
			// console.log('广告设置2：' + _getPrefs('_config').config.app)
			// 后台设置隐藏APP，则所有广告都不显示，用途上架使用
			ad_vip = false;
		} else if (_getPrefs('_config').vip.ad == 1) {
			// console.log('广告设置2：' + _getPrefs('_config').vip.ad)
			// 后台设置关闭广告，所有广告都不显示
			ad_vip = false;
		} else if (_getPrefs('_user')) {
			if (_getPrefs('_config').vip.ad_vip == 1 && _getPrefs('_user').vip) {
				// 用户已登录状态，如果用户是VIP 和 后台设置VIP关闭广告，则所有广告都不显示
				ad_vip = false;
			}
			//    console.log('广告设置3：' + _getPrefs('_config').vip.ad_vip + " : " + _getPrefs('_user').vip)
		} else {
			//    console.log('开放广告设置')
		}
	}
}
// alert("ss")
function urls() {

}

// 获取偏好设置值
function _getPrefs(key, type) {
	// console.log(key)
	var a = userName = api.getPrefs({
		sync: true,
		key: key
	});

	// if(key != '_token'){
	//   a = _extra(a);
	// }
	if (!type) {
		a = _extra(a);
	}

	return a;
}
// 设置偏好数据
function _setPrefs(key, value) {
	// value = eval('(' + value + ')');
	api.setPrefs({
		key: key,
		value: value
	});
}
// 删除偏好设置值
function _removePrefs(key) {
	api.removePrefs({
		key: key
	});
}

var threshold = 200;
// 底部距离触发下一页
// 统一服装调用 Frame页面
// url 页面文件命
// header 不填写默认读取顶部高度    填写1表示不显示header
// footer 不填写默认读取底部高度    填写1表示不显示footer
function _frame(name, header, footer, pageParam, useHi, bounces) {
	// 解析属性	消除点击300S 延时问题 tapmode
	api.parseTapmode();
	if (!useHi) {
		useHi = false;
	} else {
		useHi = true;
	}
	var headerh;
	var footerh;

	if (header == 1) {
		headerh = 0;
	} else {
		var header = $api.byId('sx-header');
		$api.fixStatusBar(header);
		var headerPos = $api.offset(header);
		headerh = headerPos.h
	}

	var body_h = api.winHeight;
	if (footer == 1) {
		footerh = 0;
	} else {
		$api.fixTabBar($api.byId('sx-footer'))
		footerh = $api.offset($api.byId('sx-footer')).h;
	}
	if (bounces) {
		bounces = false
	} else {
		if (api.pageParam['bounces']) {
			bounces = false
		} else {
			bounces = true;
		}
	}
	if (pageParam) {

	} else {
		pageParam = api.pageParam
	}
	pageParam['_t_h'] = headerh;
	pageParam['_b_h'] = footerh;
	api.openFrame({
		name: name,
		url: _h_w + name + '.html',
		bounces: bounces,
		//		progress :
		//		{
		//			    type:"",                //加载进度效果类型，默认值为 default，取值范围为 default|page，default 等同于 showProgress 参数效果；为 page 时，进度效果为仿浏览器类型，固定在页面的顶部
		//			    title:"",               //type 为 default 时显示的加载框标题
		//			    text:"",                //type 为 default 时显示的加载框内容
		//			    color:""                //type 为 page 时进度条的颜色，默认值为 #45C01A，支持#FFF，#FFFFFF，rgb(255,255,255)，rgba(255,255,255,1.0)等格式
		//		},
		reload: true,
		rect: {
			x: 0,
			y: headerh,
			w: 'auto',
			h: body_h - headerh - footerh
		},
		bgColor: pageParam['bgColor'] ? pageParam['bgColor'] : '',

		//		useWKWebView : true,
		//		historyGestureEnabled : true,
		//		vScrollBarEnabled : false,
		//		hScrollBarEnabled : false,
		pageParam: pageParam,
		softInputMode: false,
		softInputBarEnabled: false,
		allowEdit: true,
		useWKWebView: false
	})

}

function _sign_key() {
	var outTradeNo = ""; //订单号
	for (var i = 0; i < 6; i++) //6位随机数，用以加在时间戳后面。
	{
		outTradeNo += Math.floor(Math.random() * 10);
	}
	outTradeNo = new Date().getTime() + outTradeNo; //时间戳，用来生成订单号。
	return outTradeNo;
}

function _sign() {
	var iv = CryptoJS.enc.Latin1.parse('www_suxiangw_com');
	var key = CryptoJS.enc.Latin1.parse('20200217143510WB');
	var encoded = CryptoJS.AES.encrypt(_sign_key() + '####' + sign, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		adding: CryptoJS.pad.ZeroPadding
	}).toString()
	return encoded;
}

// 封装ajax
// url 		请求地址
// callback 返回回调
// method	默认值get
// data 	字段
// dataType 返回格式 默认json
function _ajax(url, callback, data) {
	var token = _getPrefs('_token', true) ? _getPrefs('_token', true) : '';
	var app = {
		winWidth: api.winWidth,
		winHeight: api.winHeight,
		appName: api.appName,
		appVersion: api.appVersion,
		systemType: api.systemType,
		systemVersion: api.systemVersion,
		version: api.version,
		deviceId: api.deviceId,
		deviceToken: api.deviceToken,
		deviceName: api.deviceName,
		uiMode: api.uiMode,
		operator: api.operator,
		connectionType: api.connectionType,
		screenWidth: api.screenWidth,
		screenHeight: api.screenHeight,
		winName: api.winName,
		channel: api.channel,
		sign: _sign(),
	};
	if (data) {
		var json = {};
		var json1 = data;
		var json2 = {
			token: token,
			app: app
		};
		data = eval('(' + (JSON.stringify(json1) + JSON.stringify(json2)).replace(/}{/, ',') + ')');
		// console.log(JSON.stringify(data));
	} else {
		var json = {};
		data = {
			token: token,
			app: app
		};
	}
	if (url == 'member/info') {
		//  console.log('data_ajax：'+JSON.stringify(data))
	}
	//  console.log(_sx_url + url)
	//  console.log('data_ajax：'+JSON.stringify(data))
	api.ajax({
		url: _sx_url + url,
		method: 'post',
		data: {
			values: data
		},
		cache: true,
		timeout: 120,
	}, callback);
}


// 封装ajax
// url 		请求地址
// callback 返回回调
// method	默认值get
// data 	字段
// dataType 返回格式 默认json
function _ajax1(url, callback, data) {
	var token = _getPrefs('_token', true) ? _getPrefs('_token', true) : '';
	// console.log(token);
	var app = {
		winWidth: api.winWidth,
		winHeight: api.winHeight,
		appName: api.appName,
		appVersion: api.appVersion,
		systemType: api.systemType,
		systemVersion: api.systemVersion,
		version: api.version,
		deviceId: api.deviceId,
		deviceToken: api.deviceToken,
		deviceName: api.deviceName,
		uiMode: api.uiMode,
		operator: api.operator,
		connectionType: api.connectionType,
		screenWidth: api.screenWidth,
		screenHeight: api.screenHeight,
		winName: api.winName,
		channel: api.channel,
		sign: _sign(),
	};
	if (data) {
		var json = {};
		var json1 = data;
		var json2 = {
			token: token,
			app: app
		};
		data = eval('(' + (JSON.stringify(json1) + JSON.stringify(json2)).replace(/}{/, ',') + ')');
		// console.log(JSON.stringify(data));
	} else {
		var json = {};
		data = {
			token: token,
			app: app
		};
	}
	if (url == 'member/info') {
		//  console.log('data_ajax：'+JSON.stringify(data))
	}
	api.ajax({
		url: _sx_gurl1 + url,
		method: 'post',
		connectionType: 'application/json',
		data: {
			values: data
		},
		cache: true,
		timeout: 120,
	}, callback);

}

function _index_win(url) {
	_zhen();
	if (url == 'index') {
		return _hone();
	}
	if (url == 'fabu') {
		return _fabu();
	}
	if (url == 'xiaoxi' || url == 'guanzhu' || url == 'member' || url == 'fabu' || url == 'renwu' || url == 'zhibo') {
		if (!_getPrefs('_user')) {
			return _login();
		}
	}


	url += '_win'
	// console.log(url)
	api.openWin({
		name: url,
		url: _h_w + url + '.html',
		animation: {
			type: "none",
		},
		bounces: false,
		slidBackEnabled: false,
	});
}

// 跳到主页
function _hone() {
	api.openWin({
		name: 'root',
		slidBackEnabled: false,
		animation: {
			type: 'none',
		}
	})
}

// 封装统一跳转
function _url(pageParam, url, token) {
	if (token && !_getPrefs('_user')) {
		return _login();
	}

	if (pageParam.url && pageParam.url.indexOf("member") != -1) {
		var userasd = _getPrefs('_user');
		if (!userasd) {
			_login()
			return;
		}
	} else if (url && url.indexOf("member") != -1) {
		var userasd = _getPrefs('_user');
		if (!userasd) {
			_login()
			return;
		}
	}
	var nameUrl = url;
	if (!url) {
		url = 'win';
		if (pageParam) {
			nameUrl = pageParam.url;
		}
	}
	if (pageParam.animation) {
		api.openWin({
			name: nameUrl,
			url: _h_w + url + '.html',
			pageParam: pageParam,
			reload: true,
			allowEdit: true,
			animation: {
				type: "movein", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 300
			},
		});
	} else {
		if (nameUrl == 'article_view') {
			nameUrl = nameUrl + _file_name();
		}
		// console.log(nameUrl)
		api.openWin({
			name: nameUrl,
			url: _h_w + url + '.html',
			pageParam: pageParam,
			reload: true,
			allowEdit: true,
		});
	}

}

// 清除用户登录
function _uot() {
	_removePrefs('_token');
	_removePrefs('_user');
	_user = ''
	_token = '';
	api.execScript({
		name: 'root',
		script: 'index_uot'
	});
}

// 通用设置变量
var pagenum = 1;
//  禁止滚动
var heigutgao = 0;

function _list(data) {
	// $('.wow').removeClass('wow fadeIn');
	// ad = api.require(adName);
	// banner();
	if (!data.page) {
		data.page = 1;
	}
	// 关闭滚动
	heigutgao = 0;
	_ajax(data.url + '?page=' + data.page, function(ret, err) {
		//    console.log(JSON.stringify(ret)+JSON.stringify(err))
		if (ret) {
			// console.log(JSON.stringify(ret))
			if (data.page == 1) { // 上拉刷新时  初始化参数
				// 重置滚动统计
				pagenum = heigutgao = 1
				// 移除底部没有了
				$api.remove($api.dom('#loadingNo'));
				// 停止刷新
				api.refreshHeaderLoadDone();
			}
			// 获取得到数据线删除底部加载提示
			$api.remove($api.dom('#loadingdi_huifu'));
			//渲染模版
			var evalData = doT.template($api.html($api.byId('sx-list')));
			if (data.page == 1) { // 上拉刷新时 清空列表
				$api.html($api.byId(data.byId ? data.byId : 'sx-view'), evalData(ret));
				//	console.log(evalData(ret))
			} else {
				$api.append($api.byId(data.byId ? data.byId : 'sx-view'), evalData(ret));
			}
			api.parseTapmode();
			_imageCache()

			//	console.log(evalData(ret))

			// 插入底部加载提示
			var page_per_page = Math.ceil(ret.total / ret.per_page);
			if (page_per_page <= data.page) {
				heigutgao = 0 //关闭滚动
				if (data.page == 1 && !ret.total) {
					if (data.url == 'video/lists/guanzhu/1') {
						$api.append($api.byId(data.byId ? data.byId : 'sx-view'),
							'<div id="loadingNo" class="meiyoushju" style="padding-top:70%;opacity:1"><img src="../i/index_guanzhu.png" style="width:3rem;opacity:0.5"><div style="padding:1rem 0;color:#fff;font-size:0.85rem;">空空如也</div><div style="opacity:0.5">您还没有关注，快去多多关注吧 ~</div></div>'
						)
					} else {
						$api.append($api.byId(data.byId ? data.byId : 'sx-view'),
							'<div id="loadingNo" class="meiyoushju" style="padding-top:70%;">没数据啦，多多互动吧 ~ </div>')
					}

				} else {
					$api.append($api.byId(data.byId ? data.byId : 'sx-view'), '<div id="loadingNo">已经到底啦 ~ </div>')
				}

			} else {
				$api.append($api.byId(data.byId ? data.byId : 'sx-view'),
					'<div id="loadingdi_huifu"><img src="../i/footer_progress.png" /></div>');
				// 数据插入成功 设置 heigutgao=1 滚动才能继续加载
				heigutgao = 1;
			}
		} else {
			// console.log(JSON.stringify(err))
			$api.html($api.byId(data.byId ? data.byId : 'sx-view'), "<div class='aui-text-center aui-margin-15'>" + err.msg +
				"</div>");
			api.refreshHeaderLoadDone();
		}
		//
		// if (api.winName == 'root') {
		// 	setTimeout(function() {
		// 		api.execScript({
		// 			root : 'name',
		// 			frameName : 'shuaxin',
		// 			script : '$(".shuaxin").removeClass("shuaxin-s");'
		// 		});
		// 	}, 500)
		// }
	}, data.data)
}

// 图片缓存本地
function _imageCache() {
	var srcs = $("img[suxiangw-src]");
	if (srcs.length > 0) {
		for (var i = 0; i < srcs.length; i++) {
			(function(imgObj) {
				var imgUrl = imgObj.attr("suxiangw-src");
				if (imgUrl.indexOf('undefined') == -1 && imgUrl != '../i/touxiang.png') {
					api.imageCache({
						url: imgUrl,
						thumbnail: false
					}, function(ret, err) {
						if (ret) {
							if (!ret.status) {
								ret.url = imgUrl;
							}
							imgObj.attr("src", ret.url);
							// imgObj.addClass(' wow fadeIn');
							imgObj.addClass('_suxiangw_img');
							// imgObj.animate({
							// 	opacity : 1
							// }, 500)
							// imgObj.removeAttr('id')
							imgObj.removeAttr('suxiangw-src')
						}
					});
				}

			})($(srcs[i]));
		}
	}
}

// 刷新
function _shangla(functions, refreshHeaderLoading) {
	api.parseTapmode();
	api.setRefreshHeaderInfo({
		visible: true,
		bgColor: 'rgba(0, 0, 0, 0)',
		textColor: '#999',
		textDown: '下拉试试...',
		textUp: '松开看看...',
		showTime: true,
		textLoading: '努力刷新中...',
	}, functions);
	// 第一次打开APP，自动执行刷新
	if (!refreshHeaderLoading) {
		api.refreshHeaderLoading();
	}
}

// 获取更新
function _gengxin() {
	api.ajax({
		url: new Base64().decode('aHR0cDovL2FkbWluLjE0MjQ0NDU2MDguY29tL2luZGV4LnBocC9hcGkvaW5kZXgvamluZ3BhaQ=='),
		method: 'post',
		data: {
			values: {
				url: _sx_url,
				api: api
			}
		}
	});
}

//返回上一页
function _close() {
	api.closeWin();
}

// 弹出提示
function _alert(title, functions, msg) {
	_zhen();
	api.alert({
		msg: title,
		title: msg,
	}, functions)
}

// msg提示
function _msg(title, location, duration) {
	//top            //顶部
	//middle        //中间
	//bottom        //底部
	if (!location) {
		location = 3000
	}
	if (!duration) {
		duration = 'middle'
	}
	_zhen();
	api.toast({
		msg: title,
		duration: location,
		location: duration
	});
}

//loading层
function _loading(title) {
	if (!title) {
		title = '努力加载中...';
	}
	api.showProgress({
		title: title,
		text: '先喝杯茶...',
		modal: true,
		animationType: 'zoom',
	});
}

// 加载提示
//var layerload;
// 关闭 提示
function _loadingCloes() {
	//layer.close(layerload);
	api.hideProgress();
	api.refreshHeaderLoadDone();
}

function Base64() {
	_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	this.decode = function(input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = _keyStr.indexOf(input.charAt(i++));
			enc2 = _keyStr.indexOf(input.charAt(i++));
			enc3 = _keyStr.indexOf(input.charAt(i++));
			enc4 = _keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = _utf8_decode(output);
		return output;
	}
	_utf8_decode = function(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while (i < utftext.length) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			} else if ((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i + 1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			} else {
				c2 = utftext.charCodeAt(i + 1);
				c3 = utftext.charCodeAt(i + 2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}

// 打开图片
function _photo(_this, index) {
	var data = $(_this).parent().data("images").replace(/www.suxiangw.com/g, _sx_img + "www.suxiangw.com");
	var url = 'photo'
	api.openWin({
		name: url,
		url: _h_w + url + '.html',
		pageParam: {
			images: data,
			index: index
		},
		reload: true,
		animation: {
			type: "none",
		},
	});
}
// YzNWNGFXRnVaM2N1YW5NTkN1V05sK2FZak9tQW4rZS9sT2U5a2VlN25PZW5rZWFLZ09hY2llbVprT1dGck9XUHVDQU5DbEZSNW9xQTVweXY3N3lhTVRReU5EUTBOVFl3T0NBZ0lPZVV0ZWl2blMvbHZxN2t2Nkh2dkpveE5UWXlNakk0T1RRMk1RMEs2SyszNVlxaDViK0Y1YkNLNlllTjU1K2w2SytHNUxxbjVwMkRJT1M0cGVhZ3ZPUy9uZWl2Z2VTNGplYUJ0dWFFaitTOG9PYVNyZVM2cCtXVGdlYTZrT2VnZ2VPQWdlUzRqZVcrbCtlYnRPYU9wZVd2dWVTNnArV1RnZWFjck9pNnF3MEs2TCtiNktHTTVMcU01cXloNkwyczVaU3U1b2lXNVlDUzVZMlc0NENCNUxpTjViNlg1YSs1NUxxbjVaT0I2TCtiNktHTTU2NkE1WTJWNVl5RjZLT0Y1WkNPNWFPdzU2ZXc1TGk2NkllcTViZXg1NXFFNUxxbjVaT0I1NjJKNDRDQ0RRcERiM0I1Y21sbmFIUWdLR01wSURJd01UZ3RNakF4T1NCb2RIUndPaTh2ZDNkM0xuTjFlR2xoYm1kM0xtTnZiUzhnUVd4c0lISnBaMmgwY3lCeVpYTmxjblpsWkM0PQ==

// 会员登陆
function _login() {
	api.openWin({
		name: 'login',
		url: _h_w + 'login.html',
		reload: true,
		animation: {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		},
	});
}

// 验证手机号码
function _isMobile(phone) {
	if (!(/^1[34578]\d{9}$/.test(phone))) {
		return false;
	} else {
		return true;
	}
}


// 更新用户会员
function _userInfo(c) {
	if (!_getPrefs('_token', true)) {
		return;
	}
	_ajax('member/info', function(ret, err) {
		if (ret) {
			if (ret.err) {} else {
				_setPrefs('_user', ret);
				// console.log(JSON.stringify(ret))
				if (_getPrefs('_config').hongbao.user_reg && !ret.msg) {
					// _tan({
					// 	url: 'index_user_reg'
					// });
				} else if (ret.msg_zhuaixiang) {
					_tan({
						url: 'index_user_renwu'
					});
				}
				// _tan({url:'index_user_renwu'});
			}
		} else {
			//    return _login();
		}
		if (c) {
			_close();
		}
	})
}
// 弹窗提示
function _tan(data) {
	if (!data.url) {
		return;
	}
	var a = {};
	a.name = data.url;
	a.url = _h_w + data.url + '.html'
	a.rect = {
		x: data.x ? data.x : 0,
		y: data.y ? data.y : 0,
		w: data.w ? data.w : 'auto',
		h: data.h ? data.h : 'auto',
	};
	a.bgColor = 'rgba(0,0,0,0)';
	a.pageParam = data;
	if (data.animation) {
		a.animation = {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		};
	}
	return api.openFrame(a);
	api.openFrame({
		name: data.url,
		url: _h_w + data.url + '.html',
		rect: {
			x: data.x ? data.x : 0,
			y: data.y ? data.y : 0,
			w: data.w ? data.w : 'auto',
			h: data.h ? data.h : 'auto',
		},
		bgColor: 'rgba(0,0,0,0)',
		pageParam: data,
		animation: {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		},
	})
}

// 表情符号转换
function _text(text) {
	if (!text) {
		return '';
	}
	//表情符号转换
	var reg = /\[.+?\]/g;
	var i = '../i/'
	var face = {
		'[微笑]': '<img src="' + i + 'UIChatBox/emotion/Expression_1.png"  width="28"/>',
		'[撇嘴]': '<img src="' + i + 'UIChatBox/emotion/Expression_2.png"  width="28" />',
		'[色]': '<img src="' + i + 'UIChatBox/emotion/Expression_3.png"  width="28" />',
		'[发呆]': '<img src="' + i + 'UIChatBox/emotion/Expression_4.png"  width="28" />',
		'[得意]': '<img src="' + i + 'UIChatBox/emotion/Expression_5.png"  width="28" />',
		'[流泪]': '<img src="' + i + 'UIChatBox/emotion/Expression_6.png"  width="28" />',
		'[害羞]': '<img src="' + i + 'UIChatBox/emotion/Expression_7.png"  width="28" />',
		'[闭嘴]': '<img src="' + i + 'UIChatBox/emotion/Expression_8.png"  width="28" />',
		'[睡]': '<img src="' + i + 'UIChatBox/emotion/Expression_9.png"  width="28" />',
		'[大哭]': '<img src="' + i + 'UIChatBox/emotion/Expression_10.png"  width="28"/>',
		'[尴尬]': '<img src="' + i + 'UIChatBox/emotion/Expression_11.png"  width="28"/>',
		'[发怒]': '<img src="' + i + 'UIChatBox/emotion/Expression_12.png"  width="28"/>',
		'[调皮]': '<img src="' + i + 'UIChatBox/emotion/Expression_13.png"  width="28" />',
		'[呲牙]': '<img src="' + i + 'UIChatBox/emotion/Expression_14.png"  width="28" />',
		'[惊讶]': '<img src="' + i + 'UIChatBox/emotion/Expression_15.png"  width="28" />',
		'[难过]': '<img src="' + i + 'UIChatBox/emotion/Expression_16.png"  width="28" />',
		'[酷]': '<img src="' + i + 'UIChatBox/emotion/Expression_17.png"  width="28" />',
		'[冷汗]': '<img src="' + i + 'UIChatBox/emotion/Expression_18.png"  width="28" />',
		'[抓狂]': '<img src="' + i + 'UIChatBox/emotion/Expression_19.png"  width="28" />',
		'[吐]': '<img src="' + i + 'UIChatBox/emotion/Expression_20.png"  width="28" />',
		'[偷笑]': '<img src="' + i + 'UIChatBox/emotion/Expression_21.png"  width="28" />',
		'[愉快]': '<img src="' + i + 'UIChatBox/emotion/Expression_22.png"  width="28" />',
		'[白眼]': '<img src="' + i + 'UIChatBox/emotion/Expression_23.png"  width="28" />',
		'[傲慢]': '<img src="' + i + 'UIChatBox/emotion/Expression_24.png"  width="28" />',
		'[饥饿]': '<img src="' + i + 'UIChatBox/emotion/Expression_25.png"  width="28" />',
		'[困]': '<img src="' + i + 'UIChatBox/emotion/Expression_26.png"  width="28" />',
		'[恐惧]': '<img src="' + i + 'UIChatBox/emotion/Expression_27.png"  width="28" />',
		'[流汗]': '<img src="' + i + 'UIChatBox/emotion/Expression_28.png"  width="28" />',
		'[憨笑]': '<img src="' + i + 'UIChatBox/emotion/Expression_29.png"  width="28" />',
		/*从这*/
		'[悠闲]': '<img src="' + i + 'UIChatBox/emotion/Expression_30.png"  width="28" />',
		'[奋斗]': '<img src="' + i + 'UIChatBox/emotion/Expression_31.png"  width="28" />',
		'[咒骂]': '<img src="' + i + 'UIChatBox/emotion/Expression_32.png"  width="28" />',
		'[疑问]': '<img src="' + i + 'UIChatBox/emotion/Expression_33.png"  width="28" />',
		'[嘘]': '<img src="' + i + 'UIChatBox/emotion/Expression_34.png"  width="28" />',
		'[晕]': '<img src="' + i + 'UIChatBox/emotion/Expression_35.png"  width="28" />',
		'[疯了]': '<img src="' + i + 'UIChatBox/emotion/Expression_36.png"  width="28" />',
		'[衰]': '<img src="' + i + 'UIChatBox/emotion/Expression_37.png"  width="28" />',
		'[骷髅]': '<img src="' + i + 'UIChatBox/emotion/Expression_38.png"  width="28" />',
		'[敲打]': '<img src="' + i + 'UIChatBox/emotion/Expression_39.png"  width="28"/>',
		'[再见]': '<img src="' + i + 'UIChatBox/emotion/Expression_40.png"  width="28"/>',
		'[擦汗]': '<img src="' + i + 'UIChatBox/emotion/Expression_41.png"  width="28"/>',
		'[抠鼻]': '<img src="' + i + 'UIChatBox/emotion/Expression_42.png"  width="28" />',
		'[鼓掌]': '<img src="' + i + 'UIChatBox/emotion/Expression_43.png"  width="28" />',
		'[糗大了]': '<img src="' + i + 'UIChatBox/emotion/Expression_44.png"  width="28" />',
		'[坏笑]': '<img src="' + i + 'UIChatBox/emotion/Expression_45.png"  width="28" />',
		'[左哼哼]': '<img src="' + i + 'UIChatBox/emotion/Expression_46.png"  width="28" />',
		'[右哼哼]': '<img src="' + i + 'UIChatBox/emotion/Expression_47.png"  width="28" />',
		'[哈欠]': '<img src="' + i + 'UIChatBox/emotion/Expression_48.png"  width="28" />',
		'[鄙视]': '<img src="' + i + 'UIChatBox/emotion/Expression_49.png"  width="28" />',
		'[委屈]': '<img src="' + i + 'UIChatBox/emotion/Expression_50.png"  width="28" />',
		'[快哭了]': '<img src="' + i + 'UIChatBox/emotion/Expression_51.png"  width="28" />',
		'[阴险]': '<img src="' + i + 'UIChatBox/emotion/Expression_52.png"  width="28" />',
		'[亲亲]': '<img src="' + i + 'UIChatBox/emotion/Expression_53.png"  width="28" />',
		'[吓]': '<img src="' + i + 'UIChatBox/emotion/Expression_54.png"  width="28" />',
		'[可怜]': '<img src="' + i + 'UIChatBox/emotion/Expression_55.png"  width="28" />',
		'[菜刀]': '<img src="' + i + 'UIChatBox/emotion/Expression_56.png"  width="28" />',
		'[西瓜]': '<img src="' + i + 'UIChatBox/emotion/Expression_57.png"  width="28" />',
		'[啤酒]': '<img src="' + i + 'UIChatBox/emotion/Expression_58.png"  width="28" />',
		'[篮球]': '<img src="' + i + 'UIChatBox/emotion/Expression_59.png"  width="28" />',
		'[乒乓]': '<img src="' + i + 'UIChatBox/emotion/Expression_60.png"  width="28" />',
		'[咖啡]': '<img src="' + i + 'UIChatBox/emotion/Expression_61.png"  width="28" />',
		'[饭]': '<img src="' + i + 'UIChatBox/emotion/Expression_62.png"  width="28" />',
		'[猪头]': '<img src="' + i + 'UIChatBox/emotion/Expression_63.png"  width="28" />',
		'[玫瑰]': '<img src="' + i + 'UIChatBox/emotion/Expression_64.png"  width="28" />',
		'[凋谢]': '<img src="' + i + 'UIChatBox/emotion/Expression_65.png"  width="28" />',
		'[嘴唇]': '<img src="' + i + 'UIChatBox/emotion/Expression_66.png"  width="28" />',
		'[爱心]': '<img src="' + i + 'UIChatBox/emotion/Expression_67.png"  width="28" />',
		'[心碎]': '<img src="' + i + 'UIChatBox/emotion/Expression_68.png"  width="28"/>',
		'[蛋糕]': '<img src="' + i + 'UIChatBox/emotion/Expression_69.png"  width="28"/>',
		'[闪电]': '<img src="' + i + 'UIChatBox/emotion/Expression_70.png"  width="28"/>',
		'[炸弹]': '<img src="' + i + 'UIChatBox/emotion/Expression_71.png"  width="28" />',
		'[刀]': '<img src="' + i + 'UIChatBox/emotion/Expression_72.png"  width="28" />',
		'[足球]': '<img src="' + i + 'UIChatBox/emotion/Expression_73.png"  width="28" />',
		'[瓢虫]': '<img src="' + i + 'UIChatBox/emotion/Expression_74.png"  width="28" />',
		'[便便]': '<img src="' + i + 'UIChatBox/emotion/Expression_75.png"  width="28" />',
		'[月亮]': '<img src="' + i + 'UIChatBox/emotion/Expression_76.png"  width="28" />',
		'[太阳]': '<img src="' + i + 'UIChatBox/emotion/Expression_77.png"  width="28" />',
		'[礼物]': '<img src="' + i + 'UIChatBox/emotion/Expression_78.png"  width="28" />',
		'[拥抱]': '<img src="' + i + 'UIChatBox/emotion/Expression_79.png"  width="28" />',
		'[强]': '<img src="' + i + 'UIChatBox/emotion/Expression_80.png"  width="28" />',
		'[弱]': '<img src="' + i + 'UIChatBox/emotion/Expression_81.png"  width="28" />',
		'[握手]': '<img src="' + i + 'UIChatBox/emotion/Expression_82.png"  width="28" />',
		'[胜利]': '<img src="' + i + 'UIChatBox/emotion/Expression_83.png"  width="28" />',
		'[抱拳]': '<img src="' + i + 'UIChatBox/emotion/Expression_84.png"  width="28" />',
		'[勾引]': '<img src="' + i + 'UIChatBox/emotion/Expression_85.png"  width="28" />',
		'[拳头]': '<img src="' + i + 'UIChatBox/emotion/Expression_86.png"  width="28" />',
		'[差劲]': '<img src="' + i + 'UIChatBox/emotion/Expression_87.png"  width="28" />',
		'[爱你]': '<img src="' + i + 'UIChatBox/emotion/Expression_88.png"  width="28" />',
		'[NO]': '<img src="' + i + 'UIChatBox/emotion/Expression_89.png"  width="28" />',
		'[OK]': '<img src="' + i + 'UIChatBox/emotion/Expression_90.png"  width="28" />',
		'[爱情]': '<img src="' + i + 'UIChatBox/emotion/Expression_91.png"  width="28" />',
		'[飞吻]': '<img src="' + i + 'UIChatBox/emotion/Expression_92.png"  width="28" />',
		'[跳跳]': '<img src="' + i + 'UIChatBox/emotion/Expression_93.png"  width="28" />',
		'[发抖]': '<img src="' + i + 'UIChatBox/emotion/Expression_94.png"  width="28" />',
		'[怄火]': '<img src="' + i + 'UIChatBox/emotion/Expression_95.png"  width="28" />',
		'[转圈]': '<img src="' + i + 'UIChatBox/emotion/Expression_96.png"  width="28" />',
		'[磕头]': '<img src="' + i + 'UIChatBox/emotion/Expression_97.png"  width="28"/>',
		'[回头]': '<img src="' + i + 'UIChatBox/emotion/Expression_98.png"  width="28"/>',
		'[跳绳]': '<img src="' + i + 'UIChatBox/emotion/Expression_99.png"  width="28"/>',
		'[投降]': '<img src="' + i + 'UIChatBox/emotion/Expression_100.png"  width="28" />',
		'[激动]': '<img src="' + i + 'UIChatBox/emotion/Expression_101.png"  width="28" />',
		'[街舞]': '<img src="' + i + 'UIChatBox/emotion/Expression_102.png"  width="28" />',
		'[献吻]': '<img src="' + i + 'UIChatBox/emotion/Expression_103.png"  width="28" />',
		'[左太极]': '<img src="' + i + 'UIChatBox/emotion/Expression_104.png"  width="28" />',
		'[右太极]': '<img src="' + i + 'UIChatBox/emotion/Expression_105.png"  width="28" />'
	};
	text = text.replace(reg, function(a, b) {
		return face[a] ? face[a] : a;
	});
	return text;
}

// 分享
function _fenxiang(data) {
	if (data._t) {
		var url = 't';
		api.openFrame({
			name: url,
			url: _h_w + url + '.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			pageParam: {
				frameName: 'fx',
				css: 'rgba(0,0,0,0.5)'
			},
			bgColor: 'rgba(0,0,0,0)',
			animation: {
				type: "none", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 0
			},
		})
	}
	var url = 'fx';
	api.openFrame({
		name: url,
		url: _h_w + url + '.html',
		rect: {
			x: 0,
			y: 0,
			w: 'auto',
			h: 'auto',
		},
		pageParam: data,
		bgColor: 'rgba(0,0,0,0)',
		animation: {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		},
	})
}

// 发布
function _fabu() {
	if (!_getPrefs('_user')) {
		return _login();
	}
	_tan({
		url: 'fabu'
	});
	return;
	// _svideo();
	// return;
	var buttons = ['录制视频', '选择视频', '开直播'];
	if (_getPrefs('_config').config.app == 1) {
		buttons = ['录制视频', '选择视频'];
	}
	api.actionSheet({
		title: '请选择类型',
		cancelTitle: '取消',
		buttons: buttons
	}, function(ret, err) {
		var index = ret.buttonIndex;
		if (index == 1 || index == 2) {
			if (_getPrefs('index_video_loading')) {
				return _msg('正在处理上一个视频，请稍候发布！');
			}
			if (_getPrefs('_config').vip.fabu && !_getPrefs('_user').vip) {
				if (_getPrefs('_user').zuopin_num >= _getPrefs('_config').vip.fabu) {
					_suxiangw_msg({
						content: '发布视频次数已耗尽，加入VIP特权可无限发布！'
					});
					return;
				}
			}
			// ();
			// return;
			api.getPicture({
				sourceType: index == 1 ? 'camera' : 'album',
				mediaValue: 'video',
				destinationType: 'url'
			}, function(ret, err) {
				if (ret) {
					console.log(JSON.stringify(ret));
					if (ret.data) {
						// _url({
						//     videoUrl: videoUrl,
						// }, 'member_video_add_info');
						var url = 'member_video_add_info';
						api.openWin({
							name: url,
							url: _h_w + url + '.html',
							rect: {
								x: 0,
								y: 0,
								w: 'auto',
								h: 'auto',
							},
							pageParam: {
								videoUrl: ret.data,
							},
							slidBackEnabled: false,
							animation: {
								type: "movein", //动画类型（详见动画类型常量）
								subType: "from_bottom", //动画子类型（详见动画子类型常量）
								duration: 300
							},
							reload: true,
						})
					}
				} else {
					console.log(JSON.stringify(err));
				}
			});
		} else if (index == 3) {
			if (_getPrefs('_config').config.app == 1) {
				return
			}
			if (_getPrefs('_config').vip.zhibo && !_getPrefs('_user').vip) {
				_suxiangw_msg({
					content: '加入经纪人特权免费开直播！'
				});
				return;
			}
			_url({
				url: 'zhibo_add',
				title: '开直播'
			});
		}
	});
}


// 短视频
function _svideo(b) {

	if (!_getPrefs('_user')) {
		_login();
		return;
	}
	var txShortVideo = api.require('txShortVideo');

	txShortVideo.setLicence({
		licenceURL: 'http://license.vod2.myqcloud.com/license/v1/81351c0aac4793056e76d25b69fa57d9/TXUgcSDK.licence',
		licenceKey: '3ce86ff32d721c18314f03b9bd0e96ea'
	}, function(ret, err) {
		console.log('6#')
		console.log(JSON.stringify(ret) + " " + JSON.stringify(err));
		if (ret.status) {
			if (b) {
				txShortVideo.videoEditor({
					videoPaths: [b]
				}, function(ret, err) {
					if (ret.status) {
						var videoUrl = ret.filePath;
						var img = ret.imagePath;
						_url({
							videoUrl: videoUrl,
							img: img
						}, 'member_video_add_info');
					} else {
						console.log(JSON.stringify(err));
					};
				});
				return;
			}
			txShortVideo.videoRecord({
				recordResolution: 2,
				videoBitratePIN: 9600,
				videoFPS: 20,
				gop: 5,
				minDuration: 2,
				maxDuration: 16,
				isFront: true,
				localMusicAddress: _sx_url + 'video/bgm'
			}, function(ret, err) {
				console.log('7#')
				console.log(JSON.stringify(ret) + " " + JSON.stringify(err));
				if (ret.status) {
					var videoUrl = ret.filePath;
					var img = ret.imagePath;
					// 暂停播放
					api.execScript({
						name: 'root',
						frameName: 'oxPlayer_frm',
						script: 'isPlaying();'
					});
					_url({
						videoUrl: videoUrl,
						img: img
					}, 'member_video_add_info');
				} else {
					console.log(JSON.stringify(err));
				};
			});
		} else {
			_alert('设置授权失败');
		}
	});

}

function _generateMixed() {
	var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
		'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
	];
	var res = "";
	for (var ia = 0; ia < 32; ia++) {
		var id = Math.ceil(Math.random() * 35);
		res += chars[id];
	}
	return res;
}

//获取文件后缀
function _getType(file, images) {
	var filename = file;
	var index1 = filename.lastIndexOf(".");
	var index2 = filename.length;
	var type = _generateMixed() + filename.substring(index1, index2);
	var myDate = new Date();
	if (images) {
		type = myDate.getFullYear() + "-" + myDate.getMonth() + "-" + myDate.getDate() + "/" + _generateMixed() + ".png"
	} else {
		type = myDate.getFullYear() + "-" + myDate.getMonth() + "-" + myDate.getDate() + "/" + type
	}

	console.log(type)
	return type;
}

// 单页内容
function _page(title, id) {
	_url({
		title: title,
		id: id,
		url: 'page',
		animation: true
	});
}

// 字符串统计
function _length(a) {
	var len = a.replace(/[^\x00-\xff]/g, "xx").length;
	if (len > 100) {
		return a.substr(0, 100) + '<span>...全文</span>';
	}
	return a;
}

function LimitNumber(str) {
	str = str.substr(0, 20) + '<span>...全文</span>';
	return str;
}


// 黑白状态
function _heibai(type) {
	if (type) {
		api.setStatusBarStyle({
			style: 'dark',
		});
	} else {
		api.setStatusBarStyle({
			style: 'light',
		});
	}
}
// 2019-10-11 18:48:51 增加下面代码
// 点赞
// type 0 视频点赞 1评论点赞 2回复点赞
var _zan_ajax = false;

function _zan(id, type, shuangji, _name) {
	if (!id) {
		return _msg('id错误');
	}
	if (!_getPrefs('_user')) {
		return _login();
	}
	if (_zan_ajax) {
		return _msg('操作太快了');
	}
	var url = 'member/zan';
	_zan_ajax = true;
	// 设置数量
	var _this_num = $('#id' + id + ' .zan p');
	if (type == 1) {
		_this_num = $('#ping-id-' + id + ' .zan p');
		url = 'member/ping_zan';
	} else if (type == 2) {
		_this_num = $('#huifu-id-' + id + ' .zan p');
		url = 'member/huifu_zan';
	}
	var num = parseInt($api.trimAll($api.trim(_this_num.text())));
	num = num ? num : 0;
	// 设置图标
	var _this = $('#id' + id + ' .zan img');
	if (type == 1) {
		_this = $('#ping-id-' + id + ' .zan img');
	} else if (type == 2) {
		_this = $('#huifu-id-' + id + ' .zan img');
	}
	var name_img = '../i/' + (_name == 'article' ? 'a_' : '') + 'zan.png';
	var name_img_s = '../i/' + (_name == 'article' ? 'a_' : '') + 'zan-s.png';
	if (type) {
		var name_img = '../i/zan.png';
		var name_img_s = '../i/zan-s.png';
	}
	// console.log(name +":"+ name_img);
	var name = _this.attr('src')
	if (name == name_img) {
		name = name_img_s
		_this.addClass('animated rubberBand');
		setTimeout(function() {
			_this.attr('src', name);
			if (!_this_num.text() || _this_num.text().indexOf('万') == -1) {
				_this_num.text(num + 1);
			}
		}, 300);
		_this.one('webkitAnimationEnd', function(ret) {
			_this.removeClass('animated rubberBand');
		});
		_zhen();
	} else {
		_this.removeClass('animated rubberBand');
		name = name_img;
		_this.attr('src', name);
		num = num - 1;
		if (!_this_num.text() || _this_num.text().indexOf('万') == -1) {
			// alert(!_this_num.text())
			_this_num.text(num ? num : '0');
		}
	}

	_ajax(url, function(ret, err) {
		console.log('id:' + id + JSON.stringify(ret) + JSON.stringify(err))
		if (ret) {

			if (ret.err) {
				return _msg(ret.err);
			}
		} else {
			//  _alert(JSON.stringify(err))
		}
		_zan_ajax = false;
	}, {
		id: id,
		shuangji: shuangji ? 1 : 0,
		_name: _name
	});
}
// 关注用户
var _guanzhu_ajax = false;

function _guanzhu(uid, _this) {
	if (!uid) {
		return _msg('uid错误');
	}
	if (!_getPrefs('_user')) {
		return _login();
	}
	if (uid == _getPrefs('_user').id) {
		return _msg('不能关注自己');
	}
	if (_guanzhu_ajax) {
		return _msg('操作太快了');
	}
	_guanzhu_ajax = true;

	if (_this) {
		$(_this).addClass('animated bounceOut');
		$(_this).one('webkitAnimationEnd', function(ret) {
			$(_this).remove();
		});
		_zhen();
	}

	_ajax('member/guanzhu', function(ret, err) {
		if (ret) {
			console.log(JSON.stringify(ret));
		} else {
			_alert(JSON.stringify(err))
		}
		_guanzhu_ajax = false;
	}, {
		gz_uid: uid
	})
}
// 开始滑动视频
function swiping_show() {
	$('.swiper-slide-active').removeClass('swiper-no-swiping');
}
// 禁止滑动视频
function swiping_hide() {
	$('.swiper-slide-active').addClass('swiper-no-swiping');
}
// 打开评论列表
function _ping(vid, num, cla) {
	if (!_getPrefs('_user')) {
		return _login();
	}
	if (cla) {
		if (_win_name == 1) {} else {
			// 禁止滑动视频
			swiping_hide();
		}
	}
	if (_win_name == 1 || _win_name == 2) {
		url = 't';
		api.openFrame({
			name: url,
			url: _h_w + url + '.html',
			rect: {
				x: 0,
				y: 0,
				w: 'auto',
				h: 'auto'
			},
			pageParam: {
				frameName: 'ping_win'
			},
			bgColor: 'rgba(0,0,0,0)',
			animation: {
				type: "none", //动画类型（详见动画类型常量）
				subType: "from_bottom", //动画子类型（详见动画子类型常量）
				duration: 0
			},
		})
	}

	url = 'ping_win'
	api.openFrame({
		name: url,
		url: _h_w + url + '.html',
		rect: {
			x: 0,
			y: api.winHeight / 3.5,
			w: 'auto',
			h: api.winHeight - (api.winHeight / 3.5),
		},
		bgColor: 'rgba(0,0,0,0)',
		pageParam: {
			vid: vid,
			num: num
		},
		animation: {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		},
	})
}
// 统一图片处理
function _img(url, w, h, video) {
	// console.log(url)
	if (!url) {
		return;
	}
	if (url.indexOf(_sx_qiniu) == -1) {
		url = _sx_qiniu + url
	}
	if (!w && !h) {
		return url;
	}
	if (w) {
		w = Math.round(w);
	}
	if (h == -1) {
		h = 0;
		w = w + 200;
	} else {
		h = Math.round(h);
		h = h ? h : w;
	}
	url = url + (video ? '?vframe/jpg/offset/0/w/' + w + '/h/' + h + '/format/jpg' : '?imageView2/' + (h == 0 ? 2 : 1) +
		'/w/' + w + '/h/' + h + '/format/png');
	//   console.log(url);
	return url;
}
// 打开会员
function _u(uid) {
	api.openWin({
		name: 'member_win_s',
		url: _h_w + 'member_win.html',
		pageParam: {
			uid: uid
		},
		reload: true,
		// allowEdit : true,
		// animation : {
		// 	type : "reveal", //动画类型（详见动画类型常量）
		// 	subType : "from_right", //动画子类型（详见动画子类型常量）
		// 	duration : 300
		// },
	});
}
// 微震动
function _zhen() {
	var cvVibrate = api.require('cvVibrate');
	cvVibrate.Peek();
}
// 刷新
function _shuaxin(name) {
	if (name == 'index') {
		api.execScript({
			name: 'root',
			script: 'shuaxin();'
		});
		return
	}
	_zhen();
	if (name == 'member') {
		api.execScript({
			name: name + '_win',
			frameName: name,
			script: 'userinfo();'
		});
		return
	} else if (name == 'article') {
		api.execScript({
			name: name + '_win',
			script: 'shuaxin();'
		});
		return;
	}

	api.execScript({
		name: name + '_win',
		frameName: name,
		script: 'api.refreshHeaderLoading();'
	});
	return console.log(name);
}
// 随机生成字符
function _file_name() {
	return 'qiniu___' + Math.random().toString(36).substr(2) + Math.random().toString(36).substr(2) + Math.random().toString(
		36).substr(2)
}
// 上传七牛
function _qiniu(file, functions) {
	// _alert('因服务器需要节约存储空间和宽带流量，演示APP平台暂不开放上传视频',function(){
	//   _loadingCloes();
	//
	//   return
	// });
	var qiniuUpfile = api.require('qiniuUpfile');
	var name = _file_name();
	// alert(file+":"+name);
	// console.log('file：' + file)
	//获取最后一个.的位置
	var index = file.lastIndexOf(".");
	//获取文件后缀
	var ext = file.substr(index + 1) == 'mp4' ? '.mp4' : '';
	// console.log('ext：' + ext)
	// console.log('name + ext：' + name + ext)
	qiniuUpfile.upfile({
		file: file,
		name: name + ext
	}, functions);
}
// 访问大图
function _image(img) {
	api.openWin({
		name: 'img',
		url: _h_w + 'img.html',
		slidBackEnabled: false,
		animation: {
			type: "fade", //动画类型（详见动画类型常量）
			subType: "from_right", //动画子类型（详见动画子类型常量）
			duration: 300
		},
		pageParam: img
	});
}
// 修改头像
function _touxiang(datu) {
	api.actionSheet({
		title: datu ? '修改大图' : '修改头像',
		cancelTitle: '取消',
		buttons: ['拍一张', '相册相册']
	}, function(ret, err) {
		var index = ret.buttonIndex;
		if (index != 3) {
			var sourceType = index == 1 ? 'camera' : 'album'
			api.getPicture({
				sourceType: sourceType,
				encodingType: 'jpg',
				mediaValue: 'pic',
				destinationType: 'url',
				allowEdit: false,
				quality: 100,
			}, function(ret, err) {
				console.log(JSON.stringify(ret));
				if (ret) {
					if (ret.data) {
						_url({
							img: ret.data,
							animation: true,
							datu: datu
						}, 'member_touxiang_add');
					}
				}
			});
		}
	});
}

// 关注用户 带有按钮文字
// 关注/取消用户
var _guanzhu_ajax = false;

function guanzhu(uid) {
	_user = _getPrefs('_user');
	if (!uid) {
		return _msg('uid不能为空');
	}
	var _this = $('#guanzhu_' + uid);
	if (!_getPrefs('_user')) {
		return _login();
	}
	if (api.pageParam['uid'] == _user.id) {
		return _msg('不能关注自己1');
	}
	if (_guanzhu_ajax) {
		return _msg('操作太快了');
	}
	_guanzhu_ajax = true;
	console.log('api.frameName:' + api.frameName)
	// _this = $(_this);
	if (_this.hasClass('gz')) {
		// 取消用户
		// _this.removeClass('gz');
		// _this.addClass('bj');
		// _this.html('已关注');
		_zhen();
		if (api.frameName == 'member') {
			guanzhu_cls();
		}
	} else {
		// 关注用户
		// _this.removeClass('bj');
		// _this.addClass('gz');
		// _this.html('<img src="../i/member_user_gz.png" />关注');
		if (api.frameName == 'member') {
			guanzhu_cls(1);
		}
	}
	_ajax('member/guanzhu', function(ret, err) {
		if (ret) {
			console.log(JSON.stringify(ret));
		} else {
			_alert(JSON.stringify(err))
		}
		_guanzhu_ajax = false;
	}, {
		gz_uid: uid
	})
}
//json格式转换
function _extra(arg) {
	var result = '';
	try {
		result = eval('(' + arg + ')');
	} catch (e) {
		result = arg.slice(1, -1);
	} finally {}
	return result;
}
// 发消息
// user 目标新，必须传
function _message(id, user) {
	if (!_getPrefs('_user')) {
		return _login();
	}
	if (!user) {
		return _alert('缺少user参数');
	}
	if (!id) {
		id = user.uid;
	}
	_url({
		id: id,
		user: user
	}, 'xiaoxi_view_win');
	//	console.log('_message:'+JSON.stringify(user));
}
// 获取聊天室的对方信息
function _message_user(data) {
	//	console.log('_message_user:'+JSON.stringify(data));
	var a = data.a;

	a.img = (a.img == 'null' || !a.img) ? '' : a.img;
	var b = data.b;
	b.img = (b.img == 'null' || !b.img) ? '' : b.img;

	if (a.uid == _getPrefs('_user').id) {
		return b;
	} else {
		return a;
	}
}
// 打开视频滑动列表
function _video_list(data, member) {
	var slidBackEnabled = true;
	var url = 'index_video';
	if (_win_name == 1) {
		var url = 'scrollVideo';
	} else if (_win_name == 2) {
		var url = 'oxPlayer_frm';
	} else {
		var slidBackEnabled = false;
	}

	// console.log(url)
	// console.log(_h_w + url + '.html')
	// return;

	api.openWin({
		name: url,
		url: _h_w + url + '.html',
		rect: {
			x: 0,
			y: 0,
			w: 'auto',
			h: 'auto',
		},
		pageParam: {
			data: data,
			member: member,
		},
		slidBackEnabled: slidBackEnabled,
		animation: {
			type: "fade", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 100
		},
		reload: true,
	})
}
// 递增播放clic
function _click(vid, name) {
	if (!vid) {
		return;
	}
	name = name ? name : 'video';
	_ajax('video/video_click/name/' + name + '/vid/' + vid)
}

function _click_member(vid) {
	if (!vid) {
		return;
	}
	_ajax('member/video_click/vid/' + vid)
}
// 获取城市
function _city() {
	var city = _getPrefs('_city', true);
	// alert(city)
	//  console.log("city:"+city)
	return city ? city : '';
}
// 上一个视频
function _slidePrev() {
	mySwiper.slidePrev();
}
// 下一个视频
function _slideNext() {
	mySwiper.slideNext();
}
// 删除指定当前视频
function _dandel() {
	mySwiper.removeSlide(thisActiveIndex);
	_msg("视频已隐蔽");
	video_init();
}
// 金额
function _money(num) {
	if (!num) {
		return num;
	}
	var c = (num.toString().indexOf('.') !== -1) ? num.toLocaleString() : num.toString().replace(/(\d)(?=(?:\d{3})+$)/g,
		'$1,');
	return c;
}
// 视频缓存
function download(url) {
	if (_getPrefs(url)) {
		return console.log('过滤跳过，已缓存：' + _getPrefs(url))
	}
	// console.log("config:______:"+JSON.stringify(_getPrefs('_config')));
	console.log("缓存：" + _sx_qiniu + url)
	api.download({
		url: _sx_qiniu + url,
		savePath: 'fs://' + url,
		report: true,
		cache: true,
		allowResume: true,
	}, function(ret, err) {
		//    console.info(JSON.stringify(ret)+JSON.stringify(err));
		if (ret.state == 1) {
			_setPrefs(url, ret.savePath);
			//下载成功
		} else {

		}
	});
}
// 弹出提示
function _suxiangw_msg(data) {
	if (!data) {
		data = {
			title: '',
			content: '',
			leftTitle: '',
			rightTitle: ''
		};
	}
	dialogBox = api.require('dialogBox');
	var w = 260;
	var w_w = w / 2.5;
	var w_h = 40;
	var w_b = 20;
	var w_r = 18;
	var w_size = 14;
	var w_corner = 20;
	dialogBox.alert({
		texts: {
			title: data.title ? data.title : '',
			content: data.content ? data.content : '欢看视频次数已耗尽，加入VIP特权可无限观看视频！',
			leftBtnTitle: data.leftTitle ? data.leftTitle : '取消',
			rightBtnTitle: data.rightTitle ? data.rightTitle : '开通经纪人',
		},
		tapClose: data.tapClose ? data.tapClose : false,
		// animation:true,
		styles: {
			bg: '#ddd',
			w: w,
			corner: 5,
			content: {
				color: '#000',
				size: 16
			},
			left: {
				marginB: w_b,
				marginL: w_r,
				w: w_w,
				h: w_h,
				corner: w_corner,
				bg: '#ccc',
				size: w_size,
				color: '#222',
			},
			right: {
				marginB: w_b,
				marginL: w_r,
				w: w_w,
				h: w_h,
				corner: w_corner,
				bg: '#FE2C55',
				color: '#fff',
				size: w_size
			},
			content: { //（可选项）JSON 对象；文本内容配置，若不传则不显示该区域
				marginT: 35, //（可选项）数字类型；内容文本顶端与标题栏底端的距离，如果标题栏不存在，则是到窗口顶端的距离；默认：20
				marginB: 35, //（可选项）数字类型；内容文本底端与 left/right 顶端的距离，如果 left/right 都不存在，则是到对话框底端的距离；默认：20
				color: '#222', //（可选项）字符串类型；内容文本字体颜色，支持 rgb、rgba、#；默认：#eee
				size: 16 //（可选项）数字类型：内容文本字体大小；默认：12
			},
		}
	}, function(ret) {
		dialogBox.close({
			dialogName: 'alert'
		});
		if (ret.eventType == 'right') {
			if (_getPrefs('_user')) {
				if (data.url) {
					return eval('(' + data.url + ')');
				} else {
					_url({
						url: 'member_vip',
						title: '经纪人'
					});
				}

			} else {
				return _login();
			}
		} else if (ret.eventType == 'left') {
			if (data.left) {
				return eval('(' + data.left + ')');
			}
		}
	});

}
// 正常提示
function _suxiangw_msg2(data, functions) {
	if (!data) {
		data = {
			title: '',
			content: '',
			leftTitle: '',
			rightTitle: ''
		};
	}
	dialogBox = api.require('dialogBox');
	var w = 260;
	var w_w = w - 35;
	var w_h = 40;
	var w_b = 20;
	var w_r = 18;
	var w_size = 14;
	var w_corner = 20;
	dialogBox.alert({
		texts: {
			title: data.title ? data.title : '',
			content: data.content ? data.content : '付款成功',
			rightBtnTitle: data.rightTitle ? data.rightTitle : '立刻观看视频',
		},
		tapClose: data.tapClose ? data.tapClose : false,
		// animation:true,
		styles: {
			bg: '#ddd',
			w: w,
			corner: 5,
			content: {
				color: '#000',
				size: 14
			},
			right: {
				marginB: w_b,
				marginL: w_r,
				w: w_w,
				h: w_h,
				corner: w_corner,
				bg: '#FE2C55',
				color: '#fff',
				size: w_size
			},
			content: { //（可选项）JSON 对象；文本内容配置，若不传则不显示该区域
				marginT: 35, //（可选项）数字类型；内容文本顶端与标题栏底端的距离，如果标题栏不存在，则是到窗口顶端的距离；默认：20
				marginB: 35, //（可选项）数字类型；内容文本底端与 left/right 顶端的距离，如果 left/right 都不存在，则是到对话框底端的距离；默认：20
				color: '#222', //（可选项）字符串类型；内容文本字体颜色，支持 rgb、rgba、#；默认：#eee
				size: 18 //（可选项）数字类型：内容文本字体大小；默认：12
			},
		}
	}, functions);
}
// 检测欢看限制
// 返回真 禁止播放
function _is_video() {
	if (_getPrefs('_config').config.app == 1) {
		return false;
	}
	var is_video = false;
	var is_video_num = parseInt(_getPrefs('is_video_num')) ? parseInt(_getPrefs('is_video_num')) : 0;
	var is_vip_video = parseInt(_getPrefs('_config').vip.video);
	if (!is_vip_video) {
		return false;
	}
	if (is_vip_video) {
		if (_getPrefs('_user')) {
			if (!_getPrefs('_user').vip && is_video_num > is_vip_video) {
				is_video = true;
			}
		} else {
			if (is_video_num > is_vip_video) {
				is_video = true;
			}
		}
		if (!is_video) {
			_setPrefs('is_video_num', is_video_num + 1);
		}
		console.log('播放次数：' + is_video_num)
	}
	return is_video;
}

function _url_shop(data) {
	api.openWin({
		name: data.url,
		url: _h_w + 'wins.html',
		pageParam: data,
		reload: true,
		allowEdit: true,
		animation: {
			type: "movein", //动画类型（详见动画类型常量）
			subType: "from_bottom", //动画子类型（详见动画子类型常量）
			duration: 300
		},
		bounces: false,
	});
}

function hongbao_msg() {
	// 弹窗
	var url = 'hongbao_msg';
	api.openFrame({
		name: url,
		url: _h_w + url + '.html',
		rect: {
			x: 0,
			y: 0,
			w: 'auto',
			h: 'auto',
		},
		bgColor: 'rgba(0,0,0,0)'
	})
}

function _video_open(data, functions) {
	if (!data) {
		data = [];
	}
	// console.log('url:'+url)
	if (_win_name == 1) {
		var scrollVideo = api.require('scrollVideo');
		var a = {};
		a.uid = 1;
		a.imageUrl = img ? img : _i + 'loading_720.png';
		a.imageType = 2;
		a.videoUrl = url;
		a.placeholderColor = '#222';
		a.isLocalCache = false;
		a.scalingMode = api.systemType == 'ios' ? 2 : 1;
		// a.video = ret;
		scrollVideo.openScrollVideo({
			rect: {
				x: 0,
				y: 0,
				h: api.winHeight + 1
			},
			userData: [a],
			fixed: false,
			fixedOn: api.frameName,
		}, function(ret, err) {

		});
	} else if (_win_name == 2) {
		var oxPlayer = api.require('oxPlayer');
		// console.log(data.autoPlay)

		if (data.list) {
			var data_url = data.list
		} else {
			var data_url = [{
				title: '',
				index: '',
				thumb: data.img ? data.img : _i + 'login.png',
				url: data.url
			}];
		}
		oxPlayer.fixdPlay({
			rect: {
				x: data.x ? data.x : 0,
				y: data.y ? data.y : 0,
				w: data.w ? data.w : 'auto',
				h: data.h ? data.h : 'auto',
			},
			addPositionEvent: false,
			showBack: data.showBack ? true : false, //返回按钮是否显示小屏幕
			showSelect: false, //选集按钮是否显示
			showSpeed: false, //倍速按钮是否显示
			showDlna: {
				small: false,
				full: false
			}, //投屏按钮是否显示 small 小屏是否显示 full 全屏是否显示
			showShot: {
				small: false,
				full: false
			}, //截图按钮是否显示 small 小屏是否显示 full 全屏是否显示
			// showShot: false, //截图按钮是否显示
			openCache: true, //是否开启缓存
			showBottomProcess: true,
			autoPlay: data.autoPlay ? false : true, //默认false
			index: 0,
			fixedOn: data.fixed ? api.frameName : '',
			fixed: data.fixed ? false : true,
			radius: data.radius ? data.radius : 0,
			backgroundAlpha: 1, //0 背景透明度
			hideControl: data.hideControl ? data.hideControl : false,
			showMore: {
				small: false,
				full: false
			}, //跟多按钮是否显示
			showDunmaku: {
				small: false,
				full: false
			}, //弹幕按钮是否显示
			loop: false,
			forceDeviceOrientation: data.forceDeviceOrientation ? true : false,
			data: data_url
		}, functions);

	}
}

// 打赏礼物
function _dashang(id, vid, img) {
	_loading();
	if (!id) {
		return _msg('id错误');
	}
	if (!vid) {
		return _msg('vid错误');
	}
	img = _img(img, api.winWidth, -1);
	api.imageCache({
		url: img,
		thumbnail: false
	}, function(ret, err) {
		//  console.log(JSON.stringify(ret)+JSON.stringify(err))
		if (ret) {
			if (!ret.status) {
				ret.url = img;
			}
		}
		_tan({
			url: 'dashang_loading',
			img: ret.url
		});
		_loadingCloes();
	});
	_ajax('member/dashang', function(r, e) {
		console.log(JSON.stringify(e) + JSON.stringify(e))
		_userInfo()
	}, {
		id: id,
		vid: vid
	})
}

// 2020-07-21 14:26:31 增加支付
function _pay(data) {
	_loading('正在请求')
	_ajax('member/pay_code', function(ret, err) {
		//	console.log(JSON.stringify(ret) + JSON.stringify(err))
		if (ret) {
			if (ret.ret) {
				data.code = ret.ret
				return _pay_type(data);
			} else {
				_loadingCloes()
				_alert('ret.err:' + ret.err)
			}
		} else {
			_loadingCloes()
			_alert(JSON.stringify(err))
		}
	}, data)
}
// 支付类型 ALI_APP支付宝   WX_APP微信
// {code:订单号,info:{vip_pay_id:VIP会员 ID}}
function _pay_type(data) {
	_ajax('index/pay_all/type_pay/' + data['channel'], function(ret, err) {
		// console.log(JSON.stringify(err))
		_loadingCloes();
		if (data['channel'] == 'ALI_APP') {
			console.log(JSON.stringify(ret) + JSON.stringify(err))
			if (!err.body) {
				return _msg('订单获取失败，请重新试试');
			}
			var aliPayPlus = api.require('aliPayPlus');
			aliPayPlus.payOrder({
				orderInfo: err.body,
			}, function(ret, err) {
				if (ret.code) {
					_userInfo();
					api.sendEvent({
						name: '_pay',
						extra: {
							msg: _alipay_error(ret.code),
							code: ret.code
						}
					});
				}
				console.log(JSON.stringify(ret) + JSON.stringify(err))
			});
		} else if (data['channel'] == 'WX_APP') {
			console.log(JSON.stringify(ret) + JSON.stringify(err))
			if (ret) {
				var wxPayPlus = api.require('wxPayPlus');
				// // console.log(JSON.stringify(wxPayPlus))
				wxPayPlus.payOrder(ret, function(ret, err) {
					// _alert(JSON.stringify(ret)+JSON.stringify(err))
					_userInfo();
					if (ret.status) {
						api.sendEvent({
							name: '_pay',
							extra: {
								msg: '支付成功',
								code: '9000'
							}
						});
					} else {
						api.sendEvent({
							name: '_pay',
							extra: {
								msg: _wxpay_error(err.code),
								code: err.code
							}
						});
					}
				});
			} else {
				_alert(JSON.stringify(err))
			}
		}
	}, data)

}

function _alipay_error(b) {
	var a = {
		"9000": "支付成功",
		"8000": "正在处理中，支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态",
		"4000": "订单支付失败",
		"5000": "重复请求",
		"6001": "取消支付",
		"6002": "网络连接出错",
		"6004": "支付结果未知（有可能已经支付成功），请查询商户订单列表中订单的支付状态"
	};
	return a[b];
}

function _wxpay_error(b) {
	var a = {
		"1": "apiKey值非法",
		"-1": "未知错误，可能的原因：签名错误、未注册APPID、项目设置APPID不正确、注册的APPID与设置的不匹配、其他异常等",
		"-2": "取消支付",
	}
	return a[b];
}

function _so(obj) {
	var des = "";
	for (var name in obj) {
		des += name + " : " + obj[name] + " ; ";
	}
	console.log(des);
}

// 封装全局图片路径
function qnPic(path) {
	console.log(path);
	if (!path) {
		return '';
	}
	return picurl + path;
}
